package demo01 
import (
	// "fmt"
)

func twoSum(nums []int, target int) []int {
    result := []int{}
    m := make(map[int]int)
    for i,k := range nums {      
        if value,exist := m[target-k];exist {
            result = append(result,value)
            result = append(result,i)
        }
        m[k] = i
    }
    return result
}


func lengthOfLongestSubstring(s string) int {
	switch len(s) {
	case 0:
		return 0
	case 1:
		return 1
	default:
		mpStr := make(map[int]string)
		listStr := []string{string(s[0])}
		for i:=1;i<len(s);i++{
			// fmt.Println(string(s[i+1]),len(listStr))
			if string(s[i]) == string(s[i-1]) || ( len(listStr)>0 && listStr[0] == string(s[i])) {
				mpStr[len(listStr)] = StringParser(listStr)
				listStr = listStr[0:0]
			}
			for _,value := range listStr{
				if string(s[i]) == value {
					mpStr[len(listStr)] = StringParser(listStr)
					listStr = listStr[0:0]
				}
			}
			listStr = append(listStr,string(s[i]))
		}
		mpStr[len(listStr)] = StringParser(listStr)
		return MaxLength(mpStr)
	}
    
}

func StringParser(str []string) (str1 string){
	for _, v := range str{
		str1 += v
	}
	return
}

func MaxLength(mp map[int]string) int {
	var c int
	for k,_:= range mp{
		if c < k{
			c = k
		}
	}
	return c
}